<?php
/**
 * Description of RegEx
 *
 * @author      Maciej Zawieja.
 * @link        http://akvus.pl
 * @package     Akvus Framework.
 * @subpackage  Libraries.
 * @copyright   2011 All rights reserved for Maciej Zawieja.
 * @version     1.0.0 - 19.08.2011 (Framework 1.3)
 */
class RegEx implements iValidation {

    const PARAMS_QUANTITY = 1;

    protected $pattern;

    function isValid( $text )
    {
        if ( ! preg_match( $this->pattern, $text ))
                throw new ValidationException ('String does not match to the pattern.', ValidationException::NOT_VALID);
        return $this;
    }

    function setParams(array &$params)
    {
        if ( count($params) < self::PARAMS_QUANTITY )
                throw new ProgrammerException ('Too less params for RegEx validation.', 0);

        $this->pattern = $params[0];
    }

    function Pattern( $pattern = null )
    {
        if ($pattern === null) return $this->pattern;
        $this->pattern = $pattern;
        return $this;
    }
}